package com.dmooo.yxmmerchant.view.presenter;

import android.content.Context;

import com.common.mvpbase.BasePresenter;
import com.common.net.listener.HttpOnNextListener;
import com.dmooo.yxmmerchant.view.contract.UserSetContract;
import com.dmooo.yxmmerchant.view.model.UserSetModel;

import java.io.File;
import java.util.Map;

public class UserSetPrestener extends BasePresenter<UserSetContract.UserSetView> implements UserSetContract.UserSetPtr {
    private UserSetModel model;
    public UserSetPrestener(UserSetContract.UserSetView mView, Context context) {
        super(mView);
        model=new UserSetModel(context);
    }
    @Override
    public void editUserMsg(Map<String, Object> map) {
        model.editUserMsg(map, new HttpOnNextListener() {
            @Override
            public void onNext(Object o) {
                mView.editInfoSuccess();
            }

            @Override
            public void onFail(Object o) {
                if(o.toString().contains("Attempt")){
                }else {
                    mView.errorMsg(o.toString());
                }
            }

            @Override
            public void onStart() {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    public void editAvatar(File file, String token) {
        model.editAvatar(file, token, new HttpOnNextListener() {
            @Override
            public void onNext(Object o) {
                mView.editAvatarSuccess();
            }

            @Override
            public void onFail(Object o) {
                mView.errorMsg(o.toString());
            }

            @Override
            public void onStart() {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    public void changePwd(String token, String oldPwd, String newPwd, String newPwd2) {
        model.changePwd(token, oldPwd, newPwd, newPwd2, new HttpOnNextListener() {
            @Override
            public void onNext(Object o) {
                mView.changePwdSuccess();
            }

            @Override
            public void onFail(Object o) {
                mView.errorMsg(o.toString());
            }

            @Override
            public void onStart() {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    public void userAuth(String token, File img_positive, File img_opposite, String turename, String id_num) {
        model.userAuth(token, img_positive, img_opposite, turename, id_num, new HttpOnNextListener() {
            @Override
            public void onNext(Object o) {
                mView.userAuthSuccess();
            }

            @Override
            public void onFail(Object o) {
                mView.errorMsg(o.toString());
            }

            @Override
            public void onStart() {

            }

            @Override
            public void onComplete() {

            }
        });
    }
}
